using System.Collections.Generic;

using com.tc.zigbee.zcl;
using com.tc.zigbee.zcl.command;
using com.tc.util;
namespace com.tc.zigbee.zcl
{
    public class ZclMessageParser
    {
        static public AbstractZclCommand parse(short clusterId,
                byte fc, byte commandId, byte[] data)
        {

            byte csb = (byte)(0x03 & fc);
            bool cs = (csb == 1);
            if (!cs)
            {

                if (commandId == ZclConstants.ZCL_CMD_READ_RSP)
                {
                    return new ReadAttributeResponse(data);
                }
                if (commandId == ZclConstants.ZCL_CMD_CONFIG_REPORT_RSP)
                {
                    return new ConfigReportResponse(data);
                }
                if (commandId == ZclConstants.ZCL_CMD_REPORT)
                {
                    return new Report(data);
                }
                if (commandId == ZclConstants.ZCL_CMD_DEFAULT_RSP)
                {
                    //System.out.println("defaultResponse");
                }
            }
            else
            {
                if (clusterId == ZclConstants.ZCL_CLUSTER_ID_GEN_GROUPS)
                {
                    byte dir = (byte)(0x08 & fc);
                    if (commandId == 0x00 && (dir == 0x08))
                    {
                        return new AddGroupResponse(data);
                    }
                    if (commandId == 0x01 && (dir == 0x08))
                    {
                        return new ViewGroupResponse(data);
                    }
                    if (commandId == 0x02 && (dir == 0x08))
                    {
                        return new GroupMemberResponse(data);
                    }
                    if (commandId == 0x03 && (dir == 0x08))
                    {
                        return new RemoveGroupResponse(data);
                    }

                }
                if (clusterId == ZclConstants.ZCL_CLUSTER_ID_GEN_SCENES)
                {
                    byte dir = (byte)(0x08 & fc);
                    if (commandId == 0x00 && (dir == 0x08))
                    {
                        return new AddSceneResponse(data);
                    }
                    if (commandId == 0x01 && (dir == 0x08))
                    {
                        return new ViewSceneResponse(data);
                    }
                    if (commandId == 0x02 && (dir == 0x08))
                    {
                        return new RemoveSceneResponse(data);
                    }
                    if (commandId == 0x03 && (dir == 0x08))
                    {
                        return new RemoveAllSceneResponse(data);
                    }

                    if (commandId == 0x04 && (dir == 0x08))
                    {
                        return new StoreSceneResponse(data);
                    }

                    if (commandId == 0x06 && (dir == 0x08))
                    {
                        return new SceneMemberResponse(data);
                    }
                }
            }
            return null;
        }

    }
}